<?php
namespace Home\Controller;
use Think\Controller;
class QuestionController extends Controller {

    public function index(){
        $s_id = I('get.student_id');
        $s_info = M('student')->find($s_id);
        $this->assign("s_info",$s_info);
        $this->display('index');
    }

    public function getQues(){
        $num = I('post.num');
        $isRight = I('post.isRight');
        $s_id = I('post.s_id');
        $q_id =I('post.q_id');

        // $num = 1;
        // $isRight = true;
        
        // if($num<=30){
        //  $where['rank']='1';
        // }else if($num>30 && $num<=45){
        //  $where['rank']='2';
        // }else if($num>45 && $num<=50){
        //  $where['rank']='3';
        // }else{

        // }
        if($num==1){
            $time =date('Y-m-d h:i:s',time());
            $clear = array(
                'd1'=>'0',
                'd2'=>'0',
                'd3'=>'0',
                'record'=>$time,
                );
            M('student')->where("student_id='%s'",$s_id)->save($clear);
        }

        if($num<=31){
            $where['rank']='1';
            if($isRight=="true"){
                M('student')->where("student_id='%s'",$s_id)->setInc('d1');
            }
                $isRead = array('idRead'=>'1');
                M('question')->where("q_id='%s'",$q_id)->save($isRead);
        }else if($num>31 && $num<=46){
            $where['rank']='2';
            if($isRight=="true"){
                M('student')->where("student_id='%s'",$s_id)->setInc('d2');
            }
                $isRead = array('idRead'=>'1');
                M('question')->where("q_id='%s'",$q_id)->save($isRead);
        }else if($num>46 && $num<=51){
            $where['rank']='3';
            if($isRight=="true"){
                M('student')->where("student_id='%s'",$s_id)->setInc('d3');
            }
                $isRead = array('idRead'=>'1');
                M('question')->where("q_id='%s'",$q_id)->save($isRead);
        }else{
            // 跳出去
            // var_dump('haha');exit;
            // $this->redirect('Student/index', 0, '页面跳转中...');
        }

        // M('tableName')->order('rand()')->limit(3)->select();
        if($num<=50){
            $where['idRead']='0';
            // $where['goods_id']=array("in",$goods);
            $arr = M('question')->order('rand()')->where($where)->find();
            
            echo json_encode($arr,true);
        }else{
            $arr= array(
                'info'=> 'success'
                );
            echo json_encode($arr,true);
        }
    }

    public function finish(){
        $this->display('finish');
    }
}